package com.health.manage.token;

import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

/**
 * 存储当前登录用户
 */
@Slf4j
public class OperatorAware {

    private static final ThreadLocal<CurrentUser> userContext = new ThreadLocal<>();

    public static void setCurrentUser(CurrentUser sessionUser) {
        userContext.set(sessionUser);
    }

    public static void clear() {
        userContext.remove();
    }

    public static Optional<CurrentUser> getCurrentUser() {
        CurrentUser user = userContext.get();
        if (user == null) {
            return Optional.empty();
        }
        return Optional.of(user);
    }

}
